import asyncio
import edge_tts

async def main():
    # 创建 communicate 实例
    # 使用中文女声
    TEXT = "你好，这是一个 Edge TTS 的测试。"
    VOICE = "zh-CN-XiaoxiaoNeural"
    FILENAME = "output.mp3"

    # 异步方式调用 Edge TTS
    communicate = edge_tts.Communicate(TEXT, VOICE)
    
    # 保存为音频文件
    await communicate.save(FILENAME)
    print(f"已生成音频文件: {FILENAME}")

    # 获取可用的声音列表
    voices = await edge_tts.list_voices()
    print("\n可用的声音列表:")
    for voice in voices:
        if "zh-CN" in voice["ShortName"]:  # 只显示中文声音
            print(f"名称: {voice['ShortName']}")
            print(f"性别: {voice['Gender']}")
            print(f"语言: {voice['Locale']}")
            print("-" * 30)

if __name__ == "__main__":
    asyncio.run(main()) 